﻿using MediatR;
using System.CJL.API.Application.Command.StorageCommand;
using System.CJL.Infrstructre.Interface;
using System.Security.Cryptography.X509Certificates;

namespace System.CJL.API.Application.CommandHanlder.StorageCommandHandler
{
    /// <summary>
    /// 添加
    /// </summary>
    public class StorageAddCommandHandler : IRequestHandler<StorageAddCommand, int>
    {
        IStorageRepository _repository;
        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="repository"></param>
        public StorageAddCommandHandler(IStorageRepository repository)
        {
            _repository=    repository;
        }
        public async Task<int> Handle(StorageAddCommand request, CancellationToken cancellationToken)
        {
            return await _repository.Addasync(new Domain.Storage
            {
                StorageName= request.StorageName,
                StorageNumbering = request.StorageNumbering,
                StorageDate = request.StorageDate.ToUniversalTime(),
                StorageRemark = request.StorageRemark,
                DetailsName = request.DetailsName,
                DetailsNumbering = request.DetailsNumbering,
                DetailsSpec = request.DetailsSpec,
                DetailsUnit = request.DetailsUnit,
                DetailsNumber = request.DetailsNumber,
                DetailsNum = request.DetailsNum,
                WarehouseName = request.WarehouseName,
                ReservoirName = request.ReservoirName,
                LocationName = request.LocationName,
                DetailsDate = request.DetailsDate.ToUniversalTime(),
                WarehouseHead = request.WarehouseHead,
                AddName = request.AddName,
                AddTime = DateTime.Now.ToUniversalTime(),
            });
        }
    }
}
